﻿using UnityEngine;
using System.Collections;

public class playerMove : MonoBehaviour {

    public float speed;
    private int direct;
    private int oldDirect = 0;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKey (KeyCode.LeftArrow)) 
        {
            direct = 0;
            this.transform.parent.transform.Translate(Vector3.left * speed * Time.deltaTime);

        } 
        else if ((Input.GetKey (KeyCode.UpArrow))) 
        {
            direct = 3;
            this.transform.parent.transform.Translate(Vector3.up * speed * Time.deltaTime);

        }
        else if (Input.GetKey (KeyCode.RightArrow)) 
        {
            direct = 2;
            this.transform.parent.transform.Translate(Vector3.right * speed * Time.deltaTime);

        } 
        else if ((Input.GetKey (KeyCode.DownArrow))) 
        {
            direct = 1;
            this.transform.parent.transform.Translate(Vector3.down * speed * Time.deltaTime);

        }
        if (direct != oldDirect) 
        {
            this.transform.Rotate(Vector3.forward * 90 * (direct - oldDirect));
            oldDirect = direct;
        }

	}
}
